package oneroom.admin.code;

import java.io.File;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

import oneroom.admin.board.boardDao;
import oneroom.admin.board.boardModel;
import oneroom.comm.commPath;

import com.oreilly.servlet.MultipartRequest;
import com.oreilly.servlet.multipart.ByTimestampFileRenamePolicy;

public class codeService {

	/**
	 * 분기
	 * @param requests
	 * @return
	 */
	public codeModel setRequest(HttpServletRequest request){
		boolean		returnVal	=	true;
		codeModel	returnValue	=	new codeModel();
		codeDao		dao 		= 	new codeDao();
		String		gubun 		=	request.getParameter("gubun") == null ? "" :request.getParameter("gubun") ;
		if(gubun != null && gubun.equals("I")){
			 returnValue	= setParame(request);
			 returnValue.setCode(returnValue.getCode());
			 returnValue.setGubun(gubun);
			 returnValue.setReturnVal(dao.getInsert(returnValue));
		}else if(gubun != null && gubun.equals("U")){
			returnValue 	= setParame(request);
			returnValue.setGubun(gubun);
			returnValue.setReturnVal(dao.getUpdate(returnValue));
		}else if(gubun != null && gubun.equals("D")){ //삭제
			returnValue 	= setParame(request);
			returnValue.setGubun(gubun);
			returnValue.setReturnVal(dao.getDelete(returnValue));
		}else if(gubun != null && gubun.equals("DI")){
			 returnValue	= setParame(request);
			 returnValue.setHdrcode(returnValue.getHdrcode());
			 returnValue.setGubun(gubun);
			 returnValue.setReturnVal(dao.getDtlInsert(returnValue));
		}else if(gubun != null && gubun.equals("DU")){
			returnValue 	= setParame(request);
			returnValue.setHdrcode(returnValue.getHdrcode());
			returnValue.setGubun(gubun);
			returnValue.setReturnVal(dao.getDtlUpdate(returnValue));
		}else if(gubun != null && gubun.equals("DD")){ //삭제
			returnValue 	= setParame(request);
			returnValue.setHdrcode(returnValue.getHdrcode());
			returnValue.setGubun(gubun);
			returnValue.setReturnVal(dao.getDtlDelete(returnValue));
		}
		return returnValue;
	}
	
	/**
	 * 파라미터 셋팅
	 * @param request
	 * @return
	 */
	private codeModel setParame(HttpServletRequest request){
		codeModel returnValue 	= 	new codeModel();
		  returnValue.setSeq(Integer.parseInt((request.getParameter("seq") 		== null ? "0" : request.getParameter("seq"))));
		  returnValue.setHdrcode(request.getParameter("hdrcode") 				== null ? "" :request.getParameter("hdrcode"));
		  returnValue.setCode(request.getParameter("code") 						== null ? "" :request.getParameter("code"));
		  returnValue.setCodename(request.getParameter("codename")				== null ? "" :request.getParameter("codename"));
		  returnValue.setComment(request.getParameter("comment")				== null ? "" :request.getParameter("comment"));
		  returnValue.setUseyn(request.getParameter("useyn")					== null ? "" :request.getParameter("useyn"));

		  return returnValue;	
	}
}

